import Vue from 'vue'
import Router from 'vue-router'
import routers from '@/router/menuRouters'

Vue.use(Router)

/* Layout */
import Layout from '@/layout/adminIndex.vue'
import ULayout from '@/layout/userIndex.vue'

export const constantRoutes = [
  // {
  //   path: '/login',
  //   component: () => import('@/views/login/index'),
  //   hidden: true
  // },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: ULayout,
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        hidden: true,
        meta: {
          title: '用户端',
          index: 1
        },
        component: () => import('@/views/pageUser/home/index.vue')
      },
      {
        path: '/smartShelf',
        name: 'smartShelf',
        hidden: true,
        meta: {
          title: '智能货架',
          index: 2
        },
        component: () => import('@/views/pageUser/smartShelf/index.vue')
      },
      {
        path: '/materialInfo',
        name: 'materialInfo',
        hidden: true,
        meta: {
          title: '物料信息',
          index: 3
        },
        component: () => import('@/views/pageUser/materialInfo/index.vue')
      },
      {
        path: '/taskInfo',
        name: 'taskInfo',
        hidden: true,
        meta: {
          title: '我的任务',
          index: 4
        },
        component: () => import('@/views/pageUser/taskInfo/index.vue')
      },
      {
        path: '/entryExitRecords',
        name: 'entryExitRecords',
        hidden: true,
        meta: {
          title: '出入库记录',
          index: 5
        },
        component: () => import('@/views/pageUser/entryExitRecords/index.vue')
      }
    ]
  },
  {
    path: '/adminHome',
    component: Layout,
    redirect: '/shelfManage',
    children: [...routers]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
